import { request } from '@/utils/request'

interface ArticlesParams {
  tag?: string
  author?: string
  favorited?: string
  limit?: number
  offset?: number
}

interface ArticleAuth {
  username: string
  bio: string
  image: string
  following: boolean
}

export interface Article {
  slug: string
  title: string
  description: string
  body: string
  tagList: string[]
  createdAt: string
  updatedAt: string
  favorited: boolean
  favoritesCount: number
  author: ArticleAuth
}

interface ArticlesPayload {
  articles: Article[]
  articlesCount: number
}

export const getArticles = (params: ArticlesParams = {}) => {
  return request.get<ArticlesPayload>('/api/articles')
}
